package com.s3u4.demo.zookeeper.base;

import com.s3u4.demo.zookeeper.ZkConfig;
import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.Watcher;
import org.apache.zookeeper.ZooKeeper;
import org.apache.zookeeper.data.Stat;

/**
 * Created by Captain on 19/10/2017.
 */
public class WatcheClient {

    public static void main(String[] args) throws Exception {

        Watcher watcher = new Watcher() {
            @Override
            public void process(WatchedEvent event) {
                String path = event.getPath();
                System.out.println("process:" + path);
                System.out.println("State:" + event.getState());
            }
        };

        ZooKeeper zooKeeper = new ZooKeeper(ZkConfig.ZK_HOST, ZkConfig.SESSION_TIMECOUNT, watcher);
        Stat stat = new Stat();
        byte[] data = zooKeeper.getData("/demo-zookeeper/node4", watcher , stat);
        String str = new String(data);
        System.out.println(str);



//        zooKeeper.register( (watchedEvent) -> {
//            String path = watchedEvent.getPath();
//            System.out.println(path);
//            Watcher.Event.KeeperState state = watchedEvent.getState();
//
//            System.out.println("state:" + state);
//        });

    }

}
